import xFetch from './xFetch';

export async function colBindDic(bind) {
  return xFetch('/api/dic/colBindDic', {
    method: 'POST',
    body: JSON.stringify(bind),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function colUnBindDic(bind) {
  return xFetch('/api/dic/colUnBindDic', {
    method: 'POST',
    body: JSON.stringify(bind),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function getItems(id) {
  return xFetch('/api/dic/' + id + '/items', {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getDic(id) {
  return xFetch('/api/dic/' + id, {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function getDicList() {
  return xFetch('/api/dic/list', {
    method: 'GET',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  }).then(function (res) {
    return res.json();
  })
}

export async function addDic(dic) {
  return xFetch('/api/dic/add', {
    method: 'POST',
    body: JSON.stringify(dic),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function updateDic(dic) {
  return xFetch('/api/dic/update', {
    method: 'PUT',
    body: JSON.stringify(dic),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function deleteDic(id) {
  return xFetch('/api/dic/' + id, {
    method: 'DELETE',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function addItem(item) {
  return xFetch('/api/dic/item/add', {
    method: 'POST',
    body: JSON.stringify(item),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function updateItem(item) {
  return xFetch('/api/dic/item/update', {
    method: 'PUT',
    body: JSON.stringify(item),
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

export async function deleteItem(id) {
  return xFetch('/api/dic/item/' + id, {
    method: 'DELETE',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    }
  })
}

